import { createRouter, createWebHashHistory } from 'vue-router'
import nprogress from 'nprogress'
import mobileRoutes from './mobileRoutes/index'

// 关闭进度条spinner
nprogress.configure({ showSpinner: false })

// 根据机器的不同使用不同的路由
// 通过像素宽度判断
// const isMobile = window.innerWidth <= 768

const routes = mobileRoutes

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

//  路由守卫
router.beforeEach((to, _from, next) => {
  nprogress.start()
  // 设置标题
  if (to.meta.title) {
    document.title = to.meta.title as string
  }

  next()
})

router.afterEach(() => {
  setTimeout(() => {
    nprogress.done()
  }, 200)
})

export default router
